<template>
  <a-card :bordered="false">

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <!-- 启用、下游引用不可操作 -->
      <a-button @click="addClassify" type="primary" icon="plus" :disabled="currentRecord.isEnable === 'Y' || currentRecord.allowEdit === 'N'">添加分区</a-button>
      <a-upload name="file" :data="queryParam" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import" :disabled="currentRecord.isEnable === 'Y' || currentRecord.allowEdit === 'N'">配置上传</a-button>
      </a-upload>
      <a-button type="primary" icon="download" @click="handleExportXls('物流分区配置模板',url.downloadTemplate)">下载模板</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('物流分区设置分类')">导出</a-button>

      <a-dropdown v-if="selectedRowKeys.length > 0 && currentRecord.isEnable === 'N' && currentRecord.allowEdit === 'Y'">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange"
        :customRow="selectRowData">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;" :preview="0"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="remarkSlot" slot-scope="text, record">
          <j-ellipsis :value="text" :length="20"></j-ellipsis>
        </span>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)" v-if="currentRecord.isEnable === 'N' && currentRecord.allowEdit === 'Y'">编辑</a>

          <!-- <a-divider type="vertical" v-if="currentRecord.isEnable === 'N'" /> -->
          <!-- <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item v-if="currentRecord.isEnable === 'N'">
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown> -->
        </span>

      </a-table>
    </div>

    <logistics-partition-classify-modal ref="modalForm" @ok="modalFormOk"></logistics-partition-classify-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import LogisticsPartitionClassifyModal from './modules/LogisticsPartitionClassifyModal'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'

  export default {
    name: 'LogisticsPartitionClassifyList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      LogisticsPartitionClassifyModal
    },
    data () {
      return {
        description: '物流分区设置分类管理页面',
        // 表头
        model:{},
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'分区代码',
            align:"center",
            dataIndex: 'code'
          },
          {
            title:'分区名称',
            align:"center",
            dataIndex: 'name'
          },
          {
            title:'备注',
            align:"center",
            dataIndex: 'remark',
            scopedSlots: { customRender: 'remarkSlot' }
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/logistics/part/logisticsPartitionClassify/list",
          delete: "/logistics/part/logisticsPartitionClassify/delete",
          deleteBatch: "/logistics/part/logisticsPartitionClassify/deleteBatch",
          exportXlsUrl: "/logistics/part/logisticsPartitionClassify/exportXls",
          downloadTemplate: "/logistics/part/logisticsPartitionClassify/downloadTemplate",
          importExcelUrl: "logistics/part/logisticsPartitionClassify/importExcel",
        },
        disableMixinCreated : true,
        dictOptions:{},
        superFieldList:[],
        currentRecord: {}
      }
    },
    created() {
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    watch: {
      dataSource: {
        handler(val){
          this.freshPartition();
        }
      }
    },
    inject: ["freshPartition"],
    methods: {
      initDictConfig(){
      },
      selectRowData(record,index){
        const that = this
        return {
          on:{
            dblclick:() => {
              // this.handleDetail(record)
            }
          }
        }
      },
      list(record) {
        this.queryParam.partitionId=record.id;
        this.model.partitionId=record.id;
        this.currentRecord = Object.assign({}, record);
        this.visible = true;
        this.loadData();
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'partitionId',text:'分区方案id',dictCode:'hz_logistics_partition,name,id'})
        fieldList.push({type:'string',value:'code',text:'分区代码',dictCode:''})
        fieldList.push({type:'string',value:'name',text:'分区名称',dictCode:''})
        fieldList.push({type:'string',value:'remark',text:'备注',dictCode:''})
        this.superFieldList = fieldList
      },
      addClassify(){
        this.$refs.modalForm.add(this.model.partitionId);
        this.$refs.modalForm.title = "新增";
        this.$refs.modalForm.disableSubmit = false;
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>